<template>
  <basic-container>
    <iframe :src="urlPath" class="iframe" ref="iframe"></iframe>
  </basic-container>
</template>

<script>
import { addressManagement } from "@/api/transportation/demandorder";
export default {
  data() {
    return {
      urlPath: "", //iframe src 路径
    };
  },
  mounted() {
    this.iframeInit();
    this.getUrlPath();
    this.resize();
  },
  watch: {
    $route: function () {
      this.iframeInit();
      this.getUrlPath();
    },
  },
  methods: {
    // 加载浏览器窗口变化自适应
    resize() {
      window.onresize = () => {
        this.iframeInit();
      };
    },
    //iframe窗口初始化
    iframeInit() {
      const iframe = this.$refs.iframe;
      const clientHeight =
        document.documentElement.clientHeight - 165;
      if (!iframe) return;
      iframe.style.height = `${clientHeight}px`;
      if (iframe.attachEvent) {
        iframe.attachEvent("onload", () => {
          // this.hide();
        });
      } else {
        iframe.onload = () => {
          // this.hide();
        };
      }
    },
    getUrlPath: function () {
      //获取 iframe src 路径
      addressManagement().then((res) => {
        if (res.data.code === 200 && res.data.success) {
          this.urlPath = res.data.data;
        }
      });
    },
  },
};
</script>

<style lang="scss">
.iframe {
  width: 100%;
  height: 100%;
  border: 0;
  overflow: hidden;
  box-sizing: border-box;
}
</style>
